package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysUsersMapper;
import com.ruoyi.system.domain.SysUsers;
import com.ruoyi.system.service.ISysUsersService;

/**
 * 用户Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-12-18
 */
@Service
public class SysUsersServiceImpl implements ISysUsersService 
{
    @Autowired
    private SysUsersMapper sysUsersMapper;

    /**
     * 查询用户
     * 
     * @param id 用户主键
     * @return 用户
     */
    @Override
    public SysUsers selectSysUsersById(Long id)
    {
        return sysUsersMapper.selectSysUsersById(id);
    }

    /**
     * 查询用户列表
     * 
     * @param sysUsers 用户
     * @return 用户
     */
    @Override
    public List<SysUsers> selectSysUsersList(SysUsers sysUsers)
    {
        return sysUsersMapper.selectSysUsersList(sysUsers);
    }

    /**
     * 校验email是否唯一
     *
     * @param sysUsers 用户信息
     * @return
     */
    @Override
    public String checkEmailUnique(SysUsers sysUsers)
    {
        Long userId = StringUtils.isNull(sysUsers.getId()) ? -1L : sysUsers.getId();
        SysUsers info = sysUsersMapper.checkEmailUnique(sysUsers.getEmail());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != userId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
    /**
     * 新增用户
     * 
     * @param sysUsers 用户
     * @return 结果
     */
    @Override
    public int insertSysUsers(SysUsers sysUsers)
    {
        return sysUsersMapper.insertSysUsers(sysUsers);
    }

    /**
     * 修改用户
     * 
     * @param sysUsers 用户
     * @return 结果
     */
    @Override
    public int updateSysUsers(SysUsers sysUsers)
    {
        return sysUsersMapper.updateSysUsers(sysUsers);
    }

    /**
     * 批量删除用户
     * 
     * @param ids 需要删除的用户主键
     * @return 结果
     */
    @Override
    public int deleteSysUsersByIds(Long[] ids)
    {
        return sysUsersMapper.deleteSysUsersByIds(ids);
    }

    /**
     * 删除用户信息
     * 
     * @param id 用户主键
     * @return 结果
     */
    @Override
    public int deleteSysUsersById(Long id)
    {
        return sysUsersMapper.deleteSysUsersById(id);
    }
}
